package com.jeeplus.itemInterface.ordersInterface;

import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.common.utils.CacheUtils;
import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.utils.IdGen;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.modules.account.entity.Account;
import com.jeeplus.modules.account.service.AccountService;
import com.jeeplus.modules.address.entity.Address;
import com.jeeplus.modules.address.service.AddressService;
import com.jeeplus.modules.cashcharge.entity.CashCharge;
import com.jeeplus.modules.cashcharge.service.CashChargeService;
import com.jeeplus.modules.goods.entity.Goods;
import com.jeeplus.modules.goods.service.GoodsService;
import com.jeeplus.modules.member.entity.Member;
import com.jeeplus.modules.member.service.MemberService;
import com.jeeplus.modules.notice.entity.Notice;
import com.jeeplus.modules.notice.service.NoticeService;
import com.jeeplus.modules.orders.entity.Orders;
import com.jeeplus.modules.orders.mapper.OrdersMapper;
import com.jeeplus.modules.orders.service.OrdersService;
import com.jeeplus.modules.plaformbank.entity.PlatformBank;
import com.jeeplus.modules.plaformbank.service.PlatformBankService;
import com.jeeplus.modules.platformcash.entity.PlatformCash;
import com.jeeplus.modules.platformcash.service.PlatformCashService;
import com.jeeplus.modules.purchaseorder.entity.PurchaseOrder;
import com.jeeplus.modules.purchaseorder.service.PurchaseOrderService;
import com.jeeplus.modules.recharge.entity.Recharge;
import com.jeeplus.modules.recharge.service.RechargeService;
import com.jeeplus.modules.tixian.entity.Tixian;
import com.jeeplus.modules.tixian.service.TixianService;
import com.jeeplus.modules.trade.entity.Trade;
import com.jeeplus.modules.trade.service.TradeService;
import com.jeeplus.modules.userbank.entity.Userbank;
import com.jeeplus.modules.userbank.service.UserbankService;
import com.jeeplus.modules.userpay.entity.Userpay;
import com.jeeplus.modules.userpay.service.UserpayService;
import com.jeeplus.modules.userwx.entity.Userwx;
import com.jeeplus.modules.userwx.service.UserwxService;
import com.jeeplus.modules.yuyue.entity.Yuyue;
import com.jeeplus.modules.yuyue.service.YuyueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import net.oschina.j2cache.redis.RedisUtils;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import redis.clients.jedis.Jedis;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;

@Api(value = "OrdersInterfaceController", description = "订单信息")
@Controller
@RequestMapping(value = "${frontPath}/orders")
public class OrdersInterfaceController {

	@Autowired
	private MemberService memberService;
	@Autowired
	private GoodsService goodsService;
	@Autowired
	private AddressService addressService;
	@Autowired
	private OrdersService ordersService;
	@Autowired
	private UserpayService userpayService;
	@Autowired
	private UserwxService userwxService;
	@Autowired
	private AccountService accountService;
	@Autowired
	private RechargeService rechargeService;
	@Autowired
	private UserbankService userbankService;
	@Autowired
	private NoticeService noticeService;
	@Autowired
	private TixianService tixianService;
	@Autowired
	private TradeService tradeService;
	@Autowired
	private YuyueService yuyueService;
	@Autowired
	private PlatformCashService platformCashService;
	@Autowired
	private OrdersMapper ordersMapper;
	@Autowired
	private PlatformBankService platformBankService;
	@Autowired
	private CashChargeService cashChargeService;
	@Autowired
	private PurchaseOrderService purchaseOrderService;

	private org.slf4j.Logger logger = LoggerFactory.getLogger(getClass());


	@ApiOperation(value = "是否可以预约",notes = "是否可以预约")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query")
	})
	@GetMapping("/isYuyue")
	@ResponseBody
	public AjaxJson isYuyue(String memberId) throws ParseException{
		AjaxJson aj = new AjaxJson();
		Member member = memberService.get(memberId);
		List<Object> list = new ArrayList<>();
		if (member!=null) {
			SimpleDateFormat df = new SimpleDateFormat("HH:mm");//设置日期格式
			Date nowTime = df.parse(df.format(new Date()));
			//洗护礼包规定时间
			Date beginTime = df.parse("09:00");
//		Date beginTime = df.parse("10:59");
			Date endTime = df.parse("09:30");
			//运动礼包规定时间
			Date beginTime1 = df.parse("14:30");
			Date endTime1 = df.parse("15:00");
			//健康礼包规定时间
			Date beginTime2 = df.parse("19:59");
			Date endTime2 = df.parse("20:30");
			//饰品礼包规定时间
			Date beginTime3 = df.parse("00:30");
			Date endTime3 = df.parse("01:00");
			//美妆礼包规定时间
			Date beginTime4 = df.parse("00:30");
			Date endTime4 = df.parse("01:00");
			//数码礼包规定时间
			Date beginTime5 = df.parse("00:30");
			Date endTime5 = df.parse("01:00");
			//调用判断方法是否在规定时间段内
			boolean isTime = DateUtils.timeCalendar(nowTime, beginTime, endTime);
			boolean isTime1 = DateUtils.timeCalendar(nowTime, beginTime1, endTime1);
			boolean isTime2 = DateUtils.timeCalendar(nowTime, beginTime2, endTime2);
//			boolean isTime3 = DateUtils.timeCalendar(nowTime, beginTime3, endTime3);
//			boolean isTime4 = DateUtils.timeCalendar(nowTime, beginTime4, endTime4);
//			boolean isTime5 = DateUtils.timeCalendar(nowTime, beginTime5, endTime5);
//			boolean isTime = true;
//			boolean isTime1 = true;
//			boolean isTime2 = false;
			boolean isTime3 = false;
			boolean isTime4 = false;
			boolean isTime5 = false;
			Yuyue yuyue = new Yuyue();
			yuyue.setMember(member);
			yuyue.setIsOver("0");
			// 0抢购  1预约  2已预约
			String flag = "";
			String flag1 = "";
			String flag2 = "";
			String flag3 = "";
			String flag4 = "";
			String flag5 = "";
			if (isTime) {
				//抢购
				flag = "0";
				Map<String, Object> map = new HashMap<>();
				map.put("goodsType", "0");
				map.put("flag", flag);
				map.put("timeRange","红酒礼包");
				map.put("time","09:00-09:30");
				map.put("appointment",56);
				map.put("pic","/ptw/userfiles/1/程序附件//pic/11.jpg");
				map.put("profit","1天/13%");
				map.put("getValue","100-800");
				list.add(map);
			} else {
				yuyue.setZone("0");
				yuyue.setIsOver("0");
				List<Yuyue> yuyueList = yuyueService.findList(yuyue);
				if (yuyueList.size()>0){
					flag = "2";
					Map<String, Object> map = new HashMap<>();
					map.put("goodsType", "0");
					map.put("flag", flag);
					map.put("timeRange","红酒礼包");
					map.put("time","09:00-09:30");
					map.put("appointment",56);
					map.put("pic","/ptw/userfiles/1/程序附件//pic/11.jpg");
					map.put("profit","1天/13%");
					map.put("getValue","100-800");
					list.add(map);
				}else {
					flag = "1";
					Map<String, Object> map = new HashMap<>();
					map.put("goodsType", "0");
					map.put("flag", flag);
					map.put("timeRange","红酒礼包");
					map.put("time","09:00-09:30");
					map.put("appointment",56);
					map.put("pic","/ptw/userfiles/1/程序附件//pic/11.jpg");
					map.put("profit","1天/13%");
					map.put("getValue","100-800");
					list.add(map);
				}

			}

			if (isTime1) {
				//可预约
				flag1 = "0";
				Map<String, Object> map = new HashMap<>();
				map.put("goodsType", "1");
				map.put("flag", flag1);
				map.put("timeRange","红酒礼包");
				map.put("time","14:30-15:00");
				map.put("appointment",126);
				map.put("pic","/ptw/userfiles/1/程序附件//pic/22.jpg");
				map.put("profit","1天/13%");
				map.put("getValue","801-1800");
				list.add(map);
			} else {
				yuyue.setZone("1");
				yuyue.setIsOver("0");
				List<Yuyue> yuyueList = yuyueService.findList(yuyue);
				if (yuyueList.size()>0){
					flag1 = "2";
					Map<String, Object> map = new HashMap<>();
					map.put("goodsType", "1");
					map.put("flag", flag1);
					map.put("timeRange","红酒礼包");
					map.put("time","14:30-15:00");
					map.put("appointment",126);
					map.put("pic","/ptw/userfiles/1/程序附件//pic/22.jpg");
					map.put("profit","1天/13%");
					map.put("getValue","801-1800");
					list.add(map);
				}else {
					flag1 = "1";
					Map<String, Object> map = new HashMap<>();
					map.put("goodsType", "1");
					map.put("flag", flag1);
					map.put("timeRange","红酒礼包");
					map.put("time","14:30-15:00");
					map.put("appointment",126);
					map.put("pic","/ptw/userfiles/1/程序附件//pic/22.jpg");
					map.put("profit","1天/13%");
					map.put("getValue","801-1800");
					list.add(map);
				}

			}

			//处于规定的时间段内
			if (isTime2) {
				//可预约
				flag2 = "0";
//				暂未开发
//				flag2 = "3";
				Map<String, Object> map = new HashMap<>();
				map.put("goodsType", "2");
				map.put("flag", flag2);
				map.put("timeRange","红酒礼包");
				map.put("time","20:00-20:30");
				map.put("appointment",210);
				map.put("pic","/ptw/userfiles/1/程序附件//pic/33.jpg");
				map.put("profit","1天/13%");
				map.put("getValue","1801-3000");
				list.add(map);
			} else {
				yuyue.setZone("2");
				yuyue.setIsOver("0");
				List<Yuyue> yuyueList = yuyueService.findList(yuyue);
				if (yuyueList.size()>0){
					flag2 = "2";
					//暂未开发
//					flag2 = "3";
					Map<String, Object> map = new HashMap<>();
					map.put("goodsType", "2");
					map.put("flag", flag2);
					map.put("timeRange","红酒礼包");
					map.put("time","20:00-20:30");
					map.put("appointment",210);
					map.put("pic","/ptw/userfiles/1/程序附件//pic/33.jpg");
					map.put("profit","1天/13%");
					map.put("getValue","1801-3000");
					list.add(map);
				}else {
					flag2 = "1";
					//暂未开发
//					flag2 = "3";
					Map<String, Object> map = new HashMap<>();
					map.put("goodsType", "2");
					map.put("flag", flag2);
					map.put("timeRange","红酒礼包");
					map.put("time","20:00-20:30");
					map.put("appointment",210);
					map.put("pic","/ptw/userfiles/1/程序附件//pic/33.jpg");
					map.put("profit","1天/13%");
					map.put("getValue","1801-3000");
					list.add(map);
				}

			}

//			if (isTime3) {
//				//可预约
////				flag3 = "0";
//				//暂未开发
//				flag3 = "3";
//				Map<String, Object> map = new HashMap<>();
//				map.put("goodsType", "3");
//				map.put("flag", flag3);
//				map.put("timeRange","红酒礼包");
//				map.put("time","00:00-00:30");
//				map.put("appointment",2000*0.08);
//				map.put("pic","/ptw/userfiles/1/程序附件//pic/44.jpg");
//				map.put("profit","1天/15%");
//				map.put("getValue","1001-2000");
//				list.add(map);
//			} else {
//				yuyue.setZone("3");
//				List<Yuyue> yuyueList = yuyueService.findList(yuyue);
//				if (yuyueList.size()>0){
////					flag3 = "2";
//					//暂未开发
//					flag3 = "3";
//					Map<String, Object> map = new HashMap<>();
//					map.put("goodsType", "3");
//					map.put("flag", flag3);
//					map.put("timeRange","红酒礼包");
//					map.put("time","00:00-00:30");
//					map.put("appointment",2000*0.08);
//					map.put("pic","/ptw/userfiles/1/程序附件//pic/44.jpg");
//					map.put("profit","1天/15%");
//					map.put("getValue","1001-2000");
//					list.add(map);
//				}else {
////					flag3 = "1";
//					//暂未开发
//					flag3 = "3";
//					Map<String, Object> map = new HashMap<>();
//					map.put("goodsType", "3");
//					map.put("flag", flag3);
//					map.put("timeRange","红酒礼包");
//					map.put("time","00:00-00:30");
//					map.put("appointment",2000*0.08);
//					map.put("pic","/ptw/userfiles/1/程序附件//pic/44.jpg");
//					map.put("profit","1天/15%");
//					map.put("getValue","1001-2000");
//					list.add(map);
//				}
//
//			}
//
//
//			if (isTime4) {
//				//可预约
////				flag4 = "0";
//				//暂未开发
//				flag4 = "3";
//				Map<String, Object> map = new HashMap<>();
//				map.put("goodsType", "4");
//				map.put("flag", flag4);
//				map.put("timeRange","红酒礼包");
//				map.put("time","00:00-00:30");
//				map.put("appointment",3000*0.08);
//				map.put("pic","/ptw/userfiles/1/程序附件//pic/55.jpg");
//				map.put("profit","1天/15%");
//				map.put("getValue","2001-3000");
//				list.add(map);
//			} else {
//				yuyue.setZone("4");
//				List<Yuyue> yuyueList = yuyueService.findList(yuyue);
//				if (yuyueList.size()>0){
////					flag4 = "2";
//					//暂未开发
//					flag4 = "3";
//					Map<String, Object> map = new HashMap<>();
//					map.put("goodsType", "4");
//					map.put("flag", flag4);
//					map.put("timeRange","红酒礼包");
//					map.put("time","00:00-00:30");
//					map.put("appointment",3000*0.08);
//					map.put("pic","/ptw/userfiles/1/程序附件//pic/55.jpg");
//					map.put("profit","1天/15%");
//					map.put("getValue","2001-3000");
//					list.add(map);
//				}else {
////					flag4 = "1";
//					//暂未开发
//					flag4 = "3";
//					Map<String, Object> map = new HashMap<>();
//					map.put("goodsType", "4");
//					map.put("flag", flag4);
//					map.put("timeRange","红酒礼包");
//					map.put("time","00:00-00:30");
//					map.put("appointment",3000*0.08);
//					map.put("pic","/ptw/userfiles/1/程序附件//pic/55.jpg");
//					map.put("profit","1天/15%");
//					map.put("getValue","2001-3000");
//					list.add(map);
//				}
//
//			}
//
//			if (isTime5) {
//				//可预约
////				flag5 = "0";
//				//暂未开发
//				flag5 = "3";
//				Map<String, Object> map = new HashMap<>();
//				map.put("goodsType", "5");
//				map.put("flag", flag5);
//				map.put("timeRange","红酒礼包");
//				map.put("time","00:00-00:30");
//				map.put("appointment",4000*0.08);
//				map.put("pic","/ptw/userfiles/1/程序附件//pic/66.jpg");
//				map.put("profit","1天/15%");
//				map.put("getValue","3001-4000");
//				list.add(map);
//			} else {
//				yuyue.setZone("5");
//				List<Yuyue> yuyueList = yuyueService.findList(yuyue);
//				if (yuyueList.size()>0){
////					flag5 = "2";
//					//暂未开发
//					flag5 = "3";
//					Map<String, Object> map = new HashMap<>();
//					map.put("goodsType", "5");
//					map.put("flag", flag5);
//					map.put("timeRange","红酒礼包");
//					map.put("time","00:00-00:30");
//					map.put("appointment",4000*0.08);
//					map.put("pic","/ptw/userfiles/1/程序附件//pic/66.jpg");
//					map.put("profit","1天/15%");
//					map.put("getValue","3001-4000");
//					list.add(map);
//				}else {
////					flag5 = "1";
//					//暂未开发
//					flag5 = "3";
//					Map<String, Object> map = new HashMap<>();
//					map.put("goodsType", "5");
//					map.put("flag", flag5);
//					map.put("timeRange","红酒礼包");
//					map.put("time","00:00-00:30");
//					map.put("appointment",4000*0.08);
//					map.put("pic","/ptw/userfiles/1/程序附件//pic/66.jpg");
//					map.put("profit","1天/15%");
//					map.put("getValue","3001-4000");
//					list.add(map);
//				}
//
//			}
		}else {
			aj.setSuccess(false);
			aj.setMsg("用户信息有误");
		}
		aj.setSuccess(true);
		aj.put("list",list);
		return aj;
	}



	@ApiOperation(value = "预约前",notes = "预约前")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "商品类型",name = "goodsType",required = true,dataType = "String",paramType = "query")
	})
	@GetMapping("/escrowYuyue")
	@ResponseBody
	public AjaxJson escrowYuyue(String memberId,String goodsType){
		AjaxJson aj = new AjaxJson();
		//查询用户信息   预约人
		Member member = memberService.get(memberId);
		if (member == null){
			aj.setSuccess(false);
			aj.setMsg("用户信息有误");
		}else {
			BigDecimal money = BigDecimal.valueOf(0);
			if ("0".equals(goodsType)){
				money = money.add(BigDecimal.valueOf(800));
			}else if ("1".equals(goodsType)){
				money = money.add(BigDecimal.valueOf(1800));
			}else if ("2".equals(goodsType)){
				money = money.add(BigDecimal.valueOf(3000));
			}
//			else if ("3".equals(goodsType)){
//				money = money.add(BigDecimal.valueOf(2000));
//			}else if ("4".equals(goodsType)){
//				money = money.add(BigDecimal.valueOf(3000));
//			}else if ("5".equals(goodsType)){
//				money = money.add(BigDecimal.valueOf(4000));
//			}
			//预约手续费为购买价格的4%
			BigDecimal charge = money.multiply(BigDecimal.valueOf(0.07));
//			if ("2".equals(goodsType)){
//				charge = money.multiply(BigDecimal.valueOf(0.1));
//			}
			aj.put("charge",charge);
			Account account = new Account();
			account.setMember(member);
			List<Account> accountList = accountService.findList(account);
			if (accountList.size()>0){
				BigDecimal balance = BigDecimal.valueOf(accountList.get(0).getYue());
				aj.put("balance",balance);
			}else {
				aj.setSuccess(false);
				aj.setMsg("钱包信息有误");
				return aj;
			}
			aj.setSuccess(true);
			aj.setMsg("操作成功");
		}
		return aj;
	}




	@ApiOperation(value = "预约商品",notes = "预约商品")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "商品分区",name = "goodsType",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "预约数量",name = "num",required = true,dataType = "int",paramType = "query"),
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query")
	})
	@GetMapping("/yuyue")
	@ResponseBody
	public AjaxJson yuyue(String goodsType, String memberId, int num) throws ParseException{

		AjaxJson aj = new AjaxJson();
		int money=0;
		if (goodsType.equals("0")){
			money=800;
		}else if (goodsType.equals("1")){
			money=1800;
		}else if (goodsType.equals("2")){
			money=3000;
		}
//		else if (goodsType.equals("3")){
//			money=2000;
//		} else if (goodsType.equals("4")){
//			money=3000;
//		} else if (goodsType.equals("5")){
//			money=4000;
//		}


		Member member = memberService.get(memberId);
		if (member!=null){
			Account account = accountService.get(member.getAccount().getId());
			if (account!=null){
				//插入预约记录
//				Yuyue yuyue=new Yuyue();
//				yuyue.setIsOver("0");
//				yuyue.setZone(goodsType);
//				yuyue.setMember(member);
//				List<Yuyue> list = yuyueService.findList(yuyue);
//				if (list.size()==0){
//				if ("2".equals(goodsType)){
//					//预约手续费 4%
//					if (account.getYue()>=money*0.1*num){
//						account.setYue(account.getYue()-money*0.1*num);
//						accountService.save(account);
//						for (int i = 0; i < num; i++) {
//							Yuyue y=new Yuyue();
//							y.setMember(member);
//							y.setIsBack("0");
//							y.setMoney(money*0.1);
//							y.setZone(goodsType);
//							y.setIsOver("0");
//							yuyueService.save(y);
//						}
//						aj.setMsg("预约成功");
//						aj.setSuccess(true);
//					}else {
//						aj.setMsg("余额不足");
//						aj.setSuccess(false);
//						return aj;
//					}
//				}else {
					//预约手续费 4%
					if (account.getYue()>=money*0.07*num){
						account.setYue(account.getYue()-money*0.07*num);
						accountService.save(account);
						for (int i = 0; i < num; i++) {
							Yuyue y=new Yuyue();
							y.setMember(member);
							y.setIsBack("0");
							y.setMoney(money*0.07);
							y.setZone(goodsType);
							y.setIsOver("0");
							yuyueService.save(y);
						}
						aj.setMsg("预约成功");
						aj.setSuccess(true);
					}else {
						aj.setMsg("余额不足");
						aj.setSuccess(false);
						return aj;
					}
//				}

//				}else {
//					aj.setMsg("您已预约过");
//					aj.setSuccess(false);
//					return aj;
//				}

			}else{
				aj.setMsg("用户信息错误");
				aj.setSuccess(false);
				return aj;
			}
		}else {
			aj.setMsg("用户信息错误");
			aj.setSuccess(false);
			return aj;
		}
		return aj;
	}






	@ApiOperation(value = "获取商品",notes = "获取商品")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "商品分类",name = "goodsType",required = false,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "页数",name = "pageNo",required = false,dataType = "String",paramType = "query")
	})
	@GetMapping("/getGoodsList")
	@ResponseBody
	public AjaxJson getGoodsList(String goodsType, String memberId, String pageNo, HttpServletRequest request, HttpServletResponse response) throws ParseException{
		Member member = memberService.get(memberId);
		AjaxJson aj = new AjaxJson();
		List<Goods> goodsList = new ArrayList<>();
		Page<Goods> page = new Page<>(1,100);
		SimpleDateFormat df = new SimpleDateFormat("HH:mm");//设置日期格式
		Date nowTime =df.parse(df.format(new Date()));
		//洗护礼包规定时间
		Date beginTime = df.parse("09:00");
//		Date beginTime = df.parse("10:59");
		Date endTime = df.parse("09:30");
		//运动礼包规定时间
		Date beginTime1 = df.parse("14:30");
		Date endTime1 = df.parse("15:00");
		//健康礼包规定时间
		Date beginTime2 = df.parse("19:59");
		Date endTime2 = df.parse("20:30");
		//饰品礼包规定时间
		Date beginTime3 = df.parse("00:30");
		Date endTime3 = df.parse("01:00");
		//美妆礼包规定时间
		Date beginTime4 = df.parse("00:30");
		Date endTime4 = df.parse("01:00");
		//数码礼包规定时间
		Date beginTime5 = df.parse("00:30");
		Date endTime5 = df.parse("01:00");
		//调用判断方法是否在规定时间段内
		boolean isTime = DateUtils.timeCalendar(nowTime, beginTime, endTime);
		boolean isTime1 = DateUtils.timeCalendar(nowTime, beginTime1, endTime1);
		boolean isTime2 = DateUtils.timeCalendar(nowTime, beginTime2, endTime2);
//		boolean isTime3 = DateUtils.timeCalendar(nowTime, beginTime3, endTime3);
//		boolean isTime4 = DateUtils.timeCalendar(nowTime, beginTime4, endTime4);
//		boolean isTime5 = DateUtils.timeCalendar(nowTime, beginTime5, endTime5);
//		boolean isTime = true;
//		boolean isTime1 = true;
//		boolean isTime2 = false;
		boolean isTime3 = false;
		boolean isTime4 = false;
		boolean isTime5 = false;



		if ("0".equals(goodsType) || StringUtils.isBlank(goodsType)){
			if(isTime){
//				goodsList.clear();
				//处于规定的时间段内
				Goods goods1 = new Goods();
				goods1.setGoodsStatus("1");
				goods1.setGoodsType("0");
				goods1.setPage(page);
				if (StringUtils.isNotBlank(pageNo)){
					page.setPageNo(Integer.parseInt(pageNo));
				}
				System.out.println("pageNo="+pageNo);
				List<Goods> list = goodsService.findList(goods1);
				page.setList(list);
				goodsList.addAll(list);
			}
		}
		if ("1".equals(goodsType) || StringUtils.isBlank(goodsType)){
			if (isTime1){
//				goodsList.clear();
				//处于规定的时间段内
				Goods goods1 = new Goods();
				goods1.setGoodsStatus("1");
				goods1.setGoodsType("1");
				goods1.setPage(page);
				if (StringUtils.isNotBlank(pageNo)){
					page.setPageNo(Integer.parseInt(pageNo));
				}
				System.out.println("pageNo="+pageNo);
				List<Goods> list = goodsService.findList(goods1);
				page.setList(list);
				goodsList.addAll(list);
			}
		}
		if ("2".equals(goodsType) || StringUtils.isBlank(goodsType)){
			//处于规定的时间段内
			if (isTime2){
//				goodsList.clear();
				Goods goods1 = new Goods();
				goods1.setGoodsStatus("1");
				goods1.setGoodsType("2");
				goods1.setPage(page);
				if (StringUtils.isNotBlank(pageNo)){
					page.setPageNo(Integer.parseInt(pageNo));
				}
				System.out.println("pageNo="+pageNo);
				List<Goods> list = goodsService.findList(goods1);
				page.setList(list);
				goodsList.addAll(list);
			}
		}
		if ("3".equals(goodsType) || StringUtils.isBlank(goodsType)){
			if (isTime3){
	//			goodsList.clear();
				//处于规定的时间段内
				Goods goods2 = new Goods();
				goods2.setGoodsStatus("1");
				goods2.setGoodsType("3");
				goods2.setPage(page);
				if (StringUtils.isNotBlank(pageNo)){
					page.setPageNo(Integer.parseInt(pageNo));
				}
				System.out.println("pageNo="+pageNo);
				List<Goods> list1 = goodsService.findList(goods2);
				page.setList(list1);
				goodsList.addAll(list1);
			}

		}
		if ("4".equals(goodsType) || StringUtils.isBlank(goodsType)){
			if(isTime4){
//				goodsList.clear();
				//处于规定的时间段内
				Goods goods1 = new Goods();
				goods1.setGoodsStatus("1");
				goods1.setGoodsType("4");
				goods1.setPage(page);
				if (StringUtils.isNotBlank(pageNo)){
					page.setPageNo(Integer.parseInt(pageNo));
				}
				System.out.println("pageNo="+pageNo);
				List<Goods> list = goodsService.findList(goods1);
				page.setList(list);
				goodsList.addAll(list);
			}
		}
		if ("5".equals(goodsType) || StringUtils.isBlank(goodsType)){
			if(isTime5){
//				goodsList.clear();
				//处于规定的时间段内
				Goods goods1 = new Goods();
				goods1.setGoodsStatus("1");
				goods1.setGoodsType("5");
				goods1.setPage(page);
				if (StringUtils.isNotBlank(pageNo)){
					page.setPageNo(Integer.parseInt(pageNo));
				}
				System.out.println("pageNo="+pageNo);
				List<Goods> list = goodsService.findList(goods1);
				page.setList(list);
				goodsList.addAll(list);
			}
		}

		//特权账号，售卖无时间限制
		if (member != null){
			if ("7".equals(member.getRemarks())){
				goodsList.clear();
				Goods goods = new Goods();
				goods.setGoodsStatus("1");
//				goods.setGoodsType("0");
				goods.setPage(page);
				if (StringUtils.isNotBlank(pageNo)){
					page.setPageNo(Integer.parseInt(pageNo));
				}
				System.out.println("pageNo="+pageNo);
				List<Goods> list = goodsService.findList(goods);


				page.setList(list);
				goodsList.addAll(list);
			}
		}


		if (goodsList.size()<=0){
			aj.setSuccess(false);
			aj.setMsg("当前商品为空！");
		}else {

			for (Goods goods1 : goodsList) {
				String[] dz = goods1.getMainImgs().split("\\|");
				goods1.setPic(dz[0]);
			}
			aj.put("goodsList",goodsList);
			aj.put("page",page);
			aj.setSuccess(true);
			aj.setMsg("操作成功！");

		}
		return aj;
	}


	@ApiOperation(value = "商品详情",notes = "商品详情")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "商品ID",name = "goodsId",required = true,dataType = "String",paramType = "query")
	})
	@GetMapping("/getGoodsDetail")
	@ResponseBody
	public AjaxJson getGoodsDetail(String goodsId){
		AjaxJson aj = new AjaxJson();
		Goods goods = goodsService.get(goodsId);
		if (goods == null){
			aj.setSuccess(false);
			aj.setMsg("商品信息有误");
		}else {
			if (StringUtils.isNotBlank(goods.getOrders().getOrdersNo())){
				Orders orders = new Orders();
				orders.setOrdersNo(goods.getOrders().getOrdersNo());
				List<Orders> ordersList = ordersService.findList(orders);
				if (ordersList.size()>0){
					Member member = memberService.get(ordersList.get(0).getMember());
					aj.put("name",member.getName());
					aj.put("mobile",member.getMobile());
				}
			}else {
				aj.put("name","");
				aj.put("mobile","");
			}
			aj.setSuccess(true);
			aj.setMsg("操作成功！");
			aj.put("goods",goods);
		}
		return aj;
	}



	@ApiOperation(value = "添加收货地址",notes = "添加收货地址")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "收件人",name = "name",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "省市区",name = "province",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "详细地址",name = "detail",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "收件人手机号",name = "mobile",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "是否默认（0否1是）",name = "isDefault",required = true,dataType = "String",paramType = "query"),

	})
	@PostMapping("/addUserAddress")
	@ResponseBody
	public AjaxJson addUserAddress(String memberId,String name,String province,String detail,String mobile,String isDefault){
		AjaxJson aj = new AjaxJson();
		//查询用户信息
		Member member = memberService.get(memberId);
		if (member == null){
			aj.setSuccess(false);
			aj.setMsg("用户信息有误");
		}else {
			Address entity = new Address();
			entity.setMember(member);
			List<Address> addressList = addressService.findList(entity);
			Address address1 = new Address();
			//用户地址为空，自动添加为默认地址
			if (addressList.size() <= 0){
				address1.setIsdefault("1");
			}else {
				if ("1".equals(isDefault)){
					for (Address address : addressList) {
						address.setIsdefault("0");
						addressService.save(address);
					}
				}
				address1.setIsdefault(isDefault);
			}
			address1.setMember(member);
			address1.setAddress(province+" "+detail);
			address1.setMobile(mobile);
			address1.setName(name);
			addressService.save(address1);
			aj.setSuccess(true);
			aj.setMsg("保存成功");
		}
		return aj;
	}

	@ApiOperation(value = "确认订单",notes = "确认订单")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "商品id",name = "goodsId",required = true,dataType = "String",paramType = "query")
	})
	@GetMapping("/confirmOrder")
	@ResponseBody
	public AjaxJson confirmOrder(String memberId,String goodsId){
		AjaxJson aj = new AjaxJson();
		//查询用户信息
		Member member = memberService.get(memberId);
		if (member == null){
			aj.setSuccess(false);
			aj.setMsg("用户信息有误");
		}else {
			//商品信息
			Goods goods = goodsService.get(goodsId);
			if (!"1".equals(goods.getGoodsStatus())){
				aj.setSuccess(false);
				aj.setMsg("该商品已购买");
				return aj;
			}
			//用户默认地址
			Address address = new Address();
			address.setMember(member);
			address.setIsdefault("1");
			List<Address> addressList = addressService.findList(address);
			if (addressList.size()>0){
				aj.put("address",addressList.get(0));
			}
			aj.put("goods",goods);
			aj.setSuccess(true);
			aj.setMsg("操作成功");
		}
		return aj;
	}



	@ApiOperation(value = "地址列表",notes = "地址列表")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query")
	})
	@GetMapping("/getAddressList")
	@ResponseBody
	public AjaxJson getAddressList(String memberId){
		AjaxJson aj = new AjaxJson();
		//查询用户信息
		Member member = memberService.get(memberId);
		if (member == null){
			aj.setSuccess(false);
			aj.setMsg("用户信息有误");
		}else {
			Address address = new Address();
			address.setMember(member);
			List<Address> list = addressService.findList(address);
			if (list.size()>0){
				for (Address address1 : list) {
					String[] dz = address1.getAddress().split(" ");
					address1.setProvince(dz[0]);
					address1.setDetail(dz[1]);
				}
			}
			aj.put("addressList",list);
			aj.setSuccess(true);
			aj.setMsg("获取成功");
		}
		return aj;
	}


	@ApiOperation(value = "选择地址",notes = "选择地址")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "地址id",name = "addressId",required = true,dataType = "String",paramType = "query")
	})
	@GetMapping("/chooseAddress")
	@ResponseBody
	public AjaxJson chooseAddress(String memberId,String addressId){
		AjaxJson aj = new AjaxJson();
		//查询用户信息
		Member member = memberService.get(memberId);
		if (member == null){
			aj.setSuccess(false);
			aj.setMsg("用户信息有误");
		}else {
			Address address = addressService.get(addressId);
			aj.put("address",address);
			aj.setSuccess(true);
			aj.setMsg("操作成功");
		}
		return aj;
	}


	@ApiOperation(value = "修改地址",notes = "修改地址")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "地址id",name = "addressId",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "收件人",name = "name",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "省市区",name = "province",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "详细地址",name = "detail",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "收件人手机号",name = "mobile",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "是否默认（0否1是）",name = "isDefault",required = true,dataType = "String",paramType = "query"),

	})
	@PostMapping("/updateUserAddress")
	@ResponseBody
	public AjaxJson updateUserAddress(String memberId,String addressId,String name,String province,String detail,String mobile,String isDefault){
		AjaxJson aj = new AjaxJson();
		//查询用户信息
		Member member = memberService.get(memberId);
		if (member == null){
			aj.setSuccess(false);
			aj.setMsg("用户信息有误");
		}else {
			Address address = addressService.get(addressId);
			if ("1".equals(isDefault)){
				Address entity = new Address();
				entity.setMember(member);
				List<Address> list = addressService.findList(entity);
				if (list.size()>0){
					for (Address address1 : list) {
						address1.setIsdefault("0");
						addressService.save(address1);
					}
				}
			}
			address.setIsdefault(isDefault);
			address.setMember(member);
			address.setAddress(province+" "+detail);
			address.setMobile(mobile);
			address.setName(name);
			addressService.save(address);
			aj.setSuccess(true);
			aj.setMsg("保存成功");
		}
		return aj;
	}


	@ApiOperation(value = "删除地址",notes = "删除地址")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "地址id",name = "addressId",required = true,dataType = "String",paramType = "query"),

	})
	@PostMapping("/deleteUserAddress")
	@ResponseBody
	public AjaxJson deleteUserAddress(String memberId,String addressId){
		AjaxJson aj = new AjaxJson();
		//查询用户信息
		Member member = memberService.get(memberId);
		if (member == null){
			aj.setSuccess(false);
			aj.setMsg("用户信息有误");
		}else {
			Address address = addressService.get(addressId);
			addressService.delete(address);
			aj.setSuccess(true);
			aj.setMsg("删除成功");
		}
		return aj;
	}

	@ApiOperation(value = "获取地址信息",notes = "获取地址信息")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "地址id",name = "addressId",required = true,dataType = "String",paramType = "query"),

	})
	@PostMapping("/getAddressDetail")
	@ResponseBody
	public AjaxJson getAddressDetail(String memberId,String addressId){
		AjaxJson aj = new AjaxJson();
		//查询用户信息
		Member member = memberService.get(memberId);
		if (member == null){
			aj.setSuccess(false);
			aj.setMsg("用户信息有误");
		}else {
			Address address = addressService.get(addressId);
			aj.setSuccess(true);
			aj.put("address",address);
		}
		return aj;
	}


	@ApiOperation(value = "获取默认地址信息",notes = "获取默认地址信息")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query"),
//			@ApiImplicitParam(value = "地址id",name = "addressId",required = true,dataType = "String",paramType = "query"),

	})
	@PostMapping("/getDefaultAddressDetail")
	@ResponseBody
	public AjaxJson getDefaultAddressDetail(String memberId){
		AjaxJson aj = new AjaxJson();
		//查询用户信息
		Member member = memberService.get(memberId);
		if (member == null){
			aj.setSuccess(false);
			aj.setMsg("用户信息有误");
		}else {
			Address address = new Address();
			address.setMember(member);
			address.setIsdefault("1");
			List<Address> list = addressService.findList(address);
			aj.setSuccess(true);
			aj.put("address",list.size()>0?list.get(0):"");
		}
		return aj;
	}


	@ApiOperation(value = "设置为默认",notes = "设置为默认")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "地址id",name = "addressId",required = true,dataType = "String",paramType = "query"),

	})
	@PostMapping("/setAddressIsDefault")
	@ResponseBody
	public AjaxJson setAddressIsDefault(String memberId,String addressId){
		AjaxJson aj = new AjaxJson();
		//查询用户信息
		Member member = memberService.get(memberId);
		if (member == null){
			aj.setSuccess(false);
			aj.setMsg("用户信息有误");
		}else {
			Address entity = new Address();
			entity.setMember(member);
			List<Address> addressList = addressService.findList(entity);
			if (addressList.size()>0){
				for (Address address : addressList) {
					address.setIsdefault("0");
					addressService.save(address);
				}
			}
			Address address = addressService.get(addressId);
			address.setIsdefault("1");
			addressService.save(address);
			aj.setSuccess(true);
		}
		return aj;
	}


	@ApiOperation(value = "提交订单",notes = "提交订单")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "商品id",name = "goodsId",required = true,dataType = "String",paramType = "query")
	})
	@PostMapping("/placeOrder")
	@ResponseBody
	public AjaxJson placeOrder(String memberId,String goodsId){
		AjaxJson aj = new AjaxJson();
		//查询用户信息
		Member member = memberService.get(memberId);
		if (member == null){
			aj.setSuccess(false);
			aj.setMsg("用户信息有误");
		}else {
//			if (!"1".equals(member.getConfirmFlag())){
//				aj.setSuccess(false);
//				aj.setMsg("您的身份认证未通过，无法购买。");
//				return aj;
//			}
			//查询购买商品信息
			Goods boughtGood = goodsService.get(goodsId);
			//防止并发提交订单-----目前测试500并发量
			Jedis jedis = new Jedis("localhost",6379);
			long count = jedis.incrBy(goodsId,1);
			if (count == 1) {
				//设置有效期10秒
				jedis.expire(goodsId,30);
			}
			if (count > 1) {
				aj.setSuccess(false);
				aj.setMsg("该商品已被购买！");
				return aj;
			}
			aj = ordersService.placeOrder(member,boughtGood);
		}
		return aj;
	}


	@ApiOperation(value = "等待付款",notes = "等待付款")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "订单编号",name = "ordersNo",required = true,dataType = "String",paramType = "query"),

	})
	@GetMapping("/waitForPaying")
	@ResponseBody
	public AjaxJson waitForPaying(String memberId,String ordersNo){
		AjaxJson aj = new AjaxJson();
		//查询用户信息
		Member member = memberService.get(memberId);
		if (member == null){
			aj.setSuccess(false);
			aj.setMsg("用户信息有误");
		}else {
			Orders orders = new Orders();
			orders.setOrdersNo(ordersNo);
			List<Orders> ordersList = ordersService.findList(orders);
			if (ordersList.size()<=0){
				aj.setSuccess(false);
				aj.setMsg("该订单不存在");
			}else {
				//出售用户信息
				Member member1 = memberService.get(ordersList.get(0).getMember());
				//打款码
				String payPic = "";
				//银行卡号
				String bankCard = "";
				//真实姓名
				String name = "";
				//开户行
				String bankName = "";
				//出售人手机号
				String phone = "";
				if (member1 != null){
					phone = member1.getMobile();
					//支付宝支付方式
					if ("0".equals(ordersList.get(0).getPayType())){
						Userpay userpay = new Userpay();
						userpay.setMember(member1);
						List<Userpay> userpayList = userpayService.findList(userpay);
						if (userpayList.size()>0){
							payPic = userpayList.get(0).getImg();
						}
					}else if ("1".equals(ordersList.get(0).getPayType())){
						//微信支付方式
						Userwx userwx = new Userwx();
						userwx.setMember(member1);
						List<Userwx> userwxList = userwxService.findList(userwx);
						if (userwxList.size()>0){
							payPic = userwxList.get(0).getImg();
						}
					}else if ("2".equals(ordersList.get(0).getPayType())){
						//微信支付方式
						Userbank userbank = new Userbank();
						userbank.setMember(member1);
						List<Userbank> userbankList = userbankService.findList(userbank);
						if (userbankList.size()>0){
							bankCard = userbankList.get(0).getBankno();
							name = userbankList.get(0).getName();
							bankName = userbankList.get(0).getBankname();
						}
					}
				}else {
					//平台用户信息
					Member user = new Member();
					user.setLoginName("admin");
					List<Member> userList = memberService.findList(user);
					//平台收款信息
					Goods goods = goodsService.get(ordersList.get(0).getGoods().getId());
					if (goods != null && goods.getPlatformCash() != null){
						PlatformCash platformCash = platformCashService.get(goods.getPlatformCash().getId());
						if (platformCash.getCashName().contains("银行卡")){
							bankCard = platformCash.getBankNo();
							name = platformCash.getPersonName();
							bankName = platformCash.getBankName();
						}else if (platformCash.getCashName().contains("支付宝")){
							payPic = "http://yvpumta.cn"+platformCash.getPayPic();
						}else if (platformCash.getCashName().contains("微信")){
							payPic = "http://yvpumta.cn"+platformCash.getWxPic();
						}
					}else if (goods.getPlatformCash() == null){
//						Userbank userbank = new Userbank();
//						userbank.setMember(userList.get(0));
//						List<Userbank> userbankList = userbankService.findList(userbank);
//						if (userbankList.size()>0){
//							bankCard = userbankList.get(0).getBankno();
//							name = userbankList.get(0).getName();
//							bankName = userbankList.get(0).getBankname();
//						}
						Userpay userpay = new Userpay();
						userpay.setMember(userList.get(0));
						List<Userpay> userpayList = userpayService.findList(userpay);
						if (userpayList.size()>0){
							payPic = userpayList.get(0).getImg();
						}
					}
					//支付宝支付方式
//					Userpay userpay = new Userpay();
//					userpay.setMember(userList.get(0));
//					List<Userpay> userpayList = userpayService.findList(userpay);
//					if (userpayList.size()>0){
//						payPic = userpayList.get(0).getImg();
//					}
//					Userbank userbank = new Userbank();
//					userbank.setMember(userList.get(0));
//					List<Userbank> userbankList = userbankService.findList(userbank);
//					if (userbankList.size()>0){
//						bankCard = userbankList.get(0).getBankno();
//						name = userbankList.get(0).getName();
//						bankName = userbankList.get(0).getBankname();
//					}
					//平台联系手机
					phone = userList.get(0).getMobile();

				}
				aj.put("bankName",bankName);
				aj.put("bankCard",bankCard);
				aj.put("name",name);
				aj.put("payPic",payPic);
				aj.put("phone",phone);
				aj.put("price",ordersList.get(0).getMoney());
				aj.setSuccess(true);
				aj.setMsg("操作成功");
			}
		}
		return aj;
	}



	@ApiOperation(value = "我已打款",notes = "我已打款")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "订单编号",name = "orderNo",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "打款图文件名",name = "paidPic",required = true,dataType = "String",paramType = "query")
	})
	@GetMapping("/alreadyPaid")
	@ResponseBody
	public AjaxJson alreadyPaid(String memberId,String orderNo,String paidPic){
		AjaxJson aj = new AjaxJson();
		//查询用户信息
		Member member = memberService.get(memberId);
		if (member == null){
			aj.setSuccess(false);
			aj.setMsg("用户信息有误");
		}else {
			if ("undefined".equals(paidPic) || StringUtils.isBlank(paidPic)){
				aj.setSuccess(false);
				aj.setMsg("当前参与人数过多，请稍后打款。");
				return aj;
			}
			aj = ordersService.alreadyPaid(orderNo,paidPic);
		}
		return aj;
	}


	@ApiOperation(value = "获取订单列表",notes = "获取订单列表")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "订单类型（0:购买订单1:出售订单）",name = "orderType",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "订单明细类型（1:待付款/出售中 2:待确认/代收款 3:已完成/待确认 4:已提货/已完成）",name = "detailType",required = true,dataType = "String",paramType = "query")
	})
	@GetMapping("/getOrdersList")
	@ResponseBody
	public AjaxJson getOrdersList(String memberId,String orderType,String detailType){
		AjaxJson aj = new AjaxJson();
		List<Orders> list = new ArrayList<>();
		//查询用户信息
		Member member = memberService.get(memberId);
		if (member == null){
			aj.setSuccess(false);
			aj.setMsg("用户信息有误");
		}else {
			//购买订单
			if ("0".equals(orderType)){
				if ("0".equals(detailType)){
					Orders orders2 = new Orders();
					//订单状态  等待付款
					orders2.setOrdersStatus("1");
					orders2.setTomem(member);
					List<Orders> ordersList2 = ordersService.findList(orders2);
					if (ordersList2.size()>0){
						for (int i = 0; i < ordersList2.size(); i++) {
							Goods goods = goodsService.get(ordersList2.get(i).getGoods().getId());
							String[] dz = goods.getMainImgs().split("\\|");
							ordersList2.get(i).setGoodsPic(dz[0]);
//						ordersList2.get(i).setGoodPrice(goods.getPrice());
							// 响应前端 待付款  6
							ordersList2.get(i).setOrdersStatus("6");
							//传前端手机号  出售
							if (ordersList2.get(i).getMember() != null){
								ordersList2.get(i).setMemPhone(ordersList2.get(i).getMember().getLoginName());
							}else {
								Member entity = new Member();
								entity.setLoginName("admin");
								List<Member> memberList = memberService.findList(entity);
								ordersList2.get(i).setMemPhone(memberList.get(0).getMobile());
							}
						}
					}
					aj.put("orderList",ordersList2);
				}else if ("1".equals(detailType)){
					//待确认
					Orders orders = new Orders();
					//订单状态  待确认
					orders.setOrdersStatus("2");
					orders.setTomem(member);
					List<Orders> ordersList = ordersService.findList(orders);
					if (ordersList.size()>0){
						for (int i = 0; i < ordersList.size(); i++) {
							Goods goods = goodsService.get(ordersList.get(i).getGoods().getId());
							String[] dz = goods.getMainImgs().split("\\|");
							ordersList.get(i).setGoodsPic(dz[0]);
//						ordersList.get(i).setGoodPrice(goods.getPrice());
							//响应前端 等待对方确认收款  0
							ordersList.get(i).setOrdersStatus("0");
							//传前端手机号  出售
							if (ordersList.get(i).getMember() != null){
								ordersList.get(i).setMemPhone(ordersList.get(i).getMember().getLoginName());
							}else {
								Member entity = new Member();
								entity.setLoginName("admin");
								List<Member> memberList = memberService.findList(entity);
								ordersList.get(i).setMemPhone(memberList.get(0).getMobile());
							}
						}
					}
					aj.put("orderList",ordersList);
				}else if ("2".equals(detailType)){
					//已完成
					Orders orders1 = new Orders();
					//订单状态   交易完成
					orders1.setOrdersStatus("3");
					//未出售
					orders1.setIsSale("1");
					orders1.setTomem(member);
					List<Orders> ordersList1 = ordersService.findList(orders1);
					if (ordersList1.size()>0){
						for (int i = 0; i < ordersList1.size(); i++) {
							Goods goods = goodsService.get(ordersList1.get(i).getGoods().getId());
							String[] dz = goods.getMainImgs().split("\\|");
							ordersList1.get(i).setGoodsPic(dz[0]);
//						ordersList1.get(i).setGoodPrice(goods.getPrice());
							//响应前端 对方已确认收款 1
							ordersList1.get(i).setOrdersStatus("1");
							//传前端手机号  出售
							if (ordersList1.get(i).getMember() != null){
								ordersList1.get(i).setMemPhone(ordersList1.get(i).getMember().getLoginName());
							}else {
								Member entity = new Member();
								entity.setLoginName("admin");
								List<Member> memberList = memberService.findList(entity);
								ordersList1.get(i).setMemPhone(memberList.get(0).getMobile());
							}
						}
					}
					aj.put("orderList",ordersList1);
				}else if ("3".equals(detailType)){
					//已提货
					Orders orders = new Orders();
					orders.setOrdersStatus("4");
					orders.setTomem(member);
					List<Orders> ordersList = ordersService.findList(orders);
					if (ordersList.size()>0){
						for (int i = 0; i < ordersList.size(); i++) {
							Goods goods = goodsService.get(ordersList.get(i).getGoods().getId());
							String[] dz = goods.getMainImgs().split("\\|");
							ordersList.get(i).setGoodsPic(dz[0]);
//						ordersList.get(i).setGoodPrice(goods.getPrice());
							//响应前端  5  已提货
							ordersList.get(i).setOrdersStatus("5");
							//传前端手机号  出售
							if (ordersList.get(i).getMember() != null){
								ordersList.get(i).setMemPhone(ordersList.get(i).getMember().getLoginName());
							}else {
								Member entity = new Member();
								entity.setLoginName("admin");
								List<Member> memberList = memberService.findList(entity);
								ordersList.get(i).setMemPhone(memberList.get(0).getMobile());
							}

						}
					}
					aj.put("orderList",ordersList);
				}else if ("4".equals(detailType)){
					//购买记录
					Orders orders1 = new Orders();
					//订单状态   交易完成   isSale   已托管出售
					orders1.setOrdersStatus("3");
					orders1.setIsSale("0");
					orders1.setTomem(member);
					List<Orders> ordersList1 = ordersService.findList(orders1);
					if (ordersList1.size()>0){
						for (int i = 0; i < ordersList1.size(); i++) {
							Goods goods = goodsService.get(ordersList1.get(i).getGoods().getId());
							String[] dz = goods.getMainImgs().split("\\|");
							ordersList1.get(i).setGoodsPic(dz[0]);
//						ordersList1.get(i).setGoodPrice(goods.getPrice());
							//响应前端 已完成  7
							ordersList1.get(i).setOrdersStatus("7");
						}
					}
					aj.put("orderList",ordersList1);
				}
			}
			if ("1".equals(orderType)){
				if ("0".equals(detailType)){
					Orders orders = new Orders();
					//上架中
					orders.setOrdersStatus("0");
					orders.setMember(member);
					List<Orders> ordersList = ordersService.findList(orders);
					if (ordersList.size()>0){
						for (int i = 0; i < ordersList.size(); i++) {
							Goods goods = goodsService.get(ordersList.get(i).getGoods().getId());
							String[] dz = goods.getMainImgs().split("\\|");
							ordersList.get(i).setGoodsPic(dz[0]);
							ordersList.get(i).setGoodPrice(goods.getPrice());
							//前端响应出售中  2
							ordersList.get(i).setOrdersStatus("2");
						}
					}
					aj.put("orderList",ordersList);
				}else if ("1".equals(detailType)){
					Orders orders1 = new Orders();
					//订单状态  等待付款
					orders1.setOrdersStatus("1");
					orders1.setMember(member);
					List<Orders> ordersList1 = ordersService.findList(orders1);
					if (ordersList1.size()>0){
						for (int i = 0; i < ordersList1.size(); i++) {
							Goods goods = goodsService.get(ordersList1.get(i).getGoods().getId());
							String[] dz = goods.getMainImgs().split("\\|");
							ordersList1.get(i).setGoodsPic(dz[0]);
							ordersList1.get(i).setGoodPrice(goods.getPrice());
							//响应前端 已出售等待买家付款  3
							ordersList1.get(i).setOrdersStatus("3");
							//传前端手机号  购买
							ordersList1.get(i).setMemPhone(ordersList1.get(i).getTomem().getLoginName());
						}
					}
					aj.put("orderList",ordersList1);
				}else if ("2".equals(detailType)){
					Orders orders2 = new Orders();
					//订单状态  待确认
					orders2.setOrdersStatus("2");
					orders2.setMember(member);
					List<Orders> ordersList2 = ordersService.findList(orders2);
					if (ordersList2.size()>0){
						for (int i = 0; i < ordersList2.size(); i++) {
							Goods goods = goodsService.get(ordersList2.get(i).getGoods().getId());
							String[] dz = goods.getMainImgs().split("\\|");
							ordersList2.get(i).setGoodsPic(dz[0]);
							ordersList2.get(i).setGoodPrice(goods.getPrice());
							//响应前端  买家已付款等待确认  4
							ordersList2.get(i).setOrdersStatus("4");
							//传前端手机号  购买
							ordersList2.get(i).setMemPhone(ordersList2.get(i).getTomem().getLoginName());
						}
					}
					aj.put("orderList",ordersList2);
				}else if ("3".equals(detailType)){
					Orders orders1 = new Orders();
					//订单状态   交易完成   isSale   已托管出售
					orders1.setOrdersStatus("3");
//					orders1.setIsSale("0");
					orders1.setMember(member);
					List<Orders> ordersList1 = ordersService.findList(orders1);
					if (ordersList1.size()>0){
						for (int i = 0; i < ordersList1.size(); i++) {
							Goods goods = goodsService.get(ordersList1.get(i).getGoods().getId());
							String[] dz = goods.getMainImgs().split("\\|");
							ordersList1.get(i).setGoodsPic(dz[0]);
//						ordersList1.get(i).setGoodPrice(goods.getPrice());
							//响应前端 已完成  7
							ordersList1.get(i).setOrdersStatus("7");
						}
					}
					aj.put("orderList",ordersList1);
				}

			}
			aj.setSuccess(true);
			aj.setMsg("操作成功");
		}
		return aj;
	}



	@ApiOperation(value = "获取订单详情",notes = "获取订单详情")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "订单编号",name = "ordersNo",required = true,dataType = "String",paramType = "query")
	})
	@GetMapping("/getOrdersDetail")
	@ResponseBody
	public AjaxJson getOrdersDetail(String memberId,String ordersType,String ordersNo){
		AjaxJson aj = new AjaxJson();
		Orders entity = new Orders();
		//查询用户信息
		Member member = memberService.get(memberId);
		if (member == null){
			aj.setSuccess(false);
			aj.setMsg("用户信息有误");
		}else {
			//购买者信息
			Member boughtUser = new Member();
			//购买者打款图
			String pic = "";
			//出售人手机号
			String phone = "";

			Orders orders = new Orders();
			orders.setOrdersNo(ordersNo);
			List<Orders> ordersList = ordersService.findList(orders);
			if (ordersList.size()>0){
				BigDecimal profit = BigDecimal.valueOf(0);
				Goods goods = goodsService.get(ordersList.get(0).getGoods().getId());
				MathContext mc = new MathContext(2, RoundingMode.HALF_DOWN);
				BigDecimal saleMoney = BigDecimal.valueOf(goods.getPrice()).divide(BigDecimal.valueOf(1.13),mc);
				profit = saleMoney.multiply(BigDecimal.valueOf(0.06)).add(profit);
//				if ("2".equals(goods.getGoodsType())){
//					saleMoney = BigDecimal.valueOf(goods.getPrice()).divide(BigDecimal.valueOf(1.25),mc);
//					profit = saleMoney.multiply(BigDecimal.valueOf(0.15)).add(profit);
//				}

				if (!"0".equals(ordersList.get(0).getOrdersStatus())){
					boughtUser = memberService.get(ordersList.get(0).getTomem().getId());
				}
				String[] dz = goods.getMainImgs().split("\\|");
				ordersList.get(0).setGoodsPic(dz[0]);
				ordersList.get(0).setGoodPrice(goods.getPrice());
				ordersList.get(0).setProfitPrice(profit.doubleValue());
				entity = ordersList.get(0);


				if (StringUtils.isNotBlank(ordersList.get(0).getImg())){
					pic = ordersList.get(0).getImg();
				}
				if (ordersList.get(0).getMember() != null){
					phone = memberService.get(ordersList.get(0).getMember().getId()).getMobile();
				}else {
					phone = "admin";
				}
			}

			aj.put("phone",phone);
			aj.put("pic",pic);
			aj.put("boughtUser",boughtUser);
			aj.put("orders",entity);
			aj.setSuccess(true);
			aj.setMsg("操作成功");
		}
		return aj;
	}



	@ApiOperation(value = "公告列表",notes = "公告列表")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query"),
	})
	@GetMapping("/noticeList")
	@ResponseBody
	public AjaxJson noticeList(String memberId){
		AjaxJson aj = new AjaxJson();
		//查询用户信息
		Member member = memberService.get(memberId);
		List<Notice> noticeList = new ArrayList<>();

		List<Notice> noticeList1 = new ArrayList<>();
		if (member == null){
			aj.setSuccess(false);
			aj.setMsg("用户信息有误");
		}else {
			List<Notice> list = noticeService.findList(new Notice());
			if (list.size()>0){
				for (Notice notice : list) {
					if ("0".equals(notice.getIstop())){
						noticeList.add(notice);
					}else {
						noticeList1.add(notice);
					}
				}
			}
			aj.put("topList",noticeList1);
			aj.put("list",noticeList);
			aj.setSuccess(true);
			aj.setMsg("操作成功");
		}
		return aj;
	}


	@ApiOperation(value = "公告详情",notes = "公告详情")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "公告id",name = "noticeId",required = true,dataType = "String",paramType = "query"),
	})
	@GetMapping("/noticeDetail")
	@ResponseBody
	public AjaxJson noticeDetail(String noticeId){
		AjaxJson aj = new AjaxJson();
		Notice notice = noticeService.get(noticeId);
		aj.put("notice",notice != null?notice : "");
		aj.setSuccess(true);
		aj.setMsg("操作成功");
		return aj;
	}

	@ApiOperation(value = "通知",notes = "通知")
	@GetMapping("/getNotice")
	@ResponseBody
	public AjaxJson getNotice(String memberId){
		AjaxJson aj = new AjaxJson();
		Notice notice = new Notice();
		notice.setRemarks("通知");
		List<Notice> list = noticeService.findList(notice);
		aj.put("notice",list.size()>0?list.get(0):"");
		aj.setSuccess(true);
		aj.setMsg("操作成功");
		return aj;
	}



	@ApiOperation(value = "确认收款",notes = "确认收款")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "订单编号",name = "ordersNo",required = true,dataType = "String",paramType = "query")
	})
	@PostMapping("/confirmCollection")
	@ResponseBody
	public AjaxJson confirmCollection(String memberId,String ordersNo){
		AjaxJson aj = new AjaxJson();
		//查询用户信息
		Member member = memberService.get(memberId);
		if (member == null){
			aj.setSuccess(false);
			aj.setMsg("用户信息有误");
		}else {
			logger.debug("===============================ordersNo:"+ordersNo);
            if(StringUtils.isNotEmpty(ordersNo)) {
            	//处理订单状态  及  对应 上级团队人数  团队业绩
            	aj = ordersService.manageOrders(member,ordersNo);
            }else {
            	aj.setSuccess(false);
            	aj.setMsg("参数错误");
            }
		}
		return aj;
	}


	@ApiOperation(value = "去充值",notes = "去充值")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query")
	})
	@GetMapping("/goToRecharge")
	@ResponseBody
	public AjaxJson goToRecharge(String memberId){
		AjaxJson aj = new AjaxJson();
		//查询用户信息
		Member member = memberService.get(memberId);
		if (member == null){
			aj.setSuccess(false);
			aj.setMsg("用户信息有误");
		}else {
			List<PlatformBank> allList = platformBankService.findAllList(new PlatformBank());
			aj.put("bankList",allList);
			aj.setSuccess(true);
			aj.setMsg("操作成功");
		}
		return aj;
	}


	@ApiOperation(value = "确认充值",notes = "确认充值")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "充值金额",name = "totalMoney",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "充值凭证",name = "rechargePic",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "充值银行id",name = "bankId",required = true,dataType = "String",paramType = "query")
//			@ApiImplicitParam(value = "openid",name = "openid",required = true,dataType = "String",paramType = "query")
	})
	@PostMapping("/confirmRecharge")
	@ResponseBody
	public AjaxJson confirmRecharge(String memberId,String totalMoney,String rechargePic,String bankId){
		AjaxJson aj = new AjaxJson();
		//查询用户信息   出售人
		Member member = memberService.get(memberId);
		if (member == null){
			aj.setSuccess(false);
			aj.setMsg("用户信息有误");
		}else {
			Jedis jedis = new Jedis();
			Long r1 = jedis.setnx(memberId+"_recharge",memberId);
			if (r1 != 1){
				aj.setSuccess(false);
				aj.setMsg("操作频繁，请稍候");
				return aj;
			}else {
				jedis.expire(memberId+"_recharge",5);
			}
			//插入充值记录
			aj = rechargeService.wxRecharge(member,totalMoney,rechargePic,bankId);
			jedis.close();
		}
		return aj;
	}



	@ApiOperation(value = "确定出售",notes = "确定出售")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "订单编号",name = "ordersNo",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "出售价格",name = "salePrice",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "手续费",name = "charge",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "收款方式（0:支付宝1:微信2:银行卡）",name = "payType",required = true,dataType = "String",paramType = "query")
	})
	@PostMapping("/confirmSale")
	@ResponseBody
	public AjaxJson confirmSale(String memberId,String ordersNo,String salePrice,String charge,String payType){
		AjaxJson aj = new AjaxJson();
		//查询用户信息   出售人
		Member member = memberService.get(memberId);
		if (member == null){
			aj.setSuccess(false);
			aj.setMsg("用户信息有误");
		}else {
			if (!"1".equals(member.getConfirmFlag())){
				aj.setSuccess(false);
				aj.setMsg("您的身份认证还未通过，无法售出。");
				return aj;
			}
			Jedis jedis = new Jedis("localhost",6379);
			long count = jedis.incrBy(ordersNo,1);
			if (count == 1) {
				//设置有效期10秒
				jedis.expire(ordersNo, 10);
				aj = ordersService.confirmSale(member,ordersNo,salePrice,charge,payType);
			}
		}
		return aj;
	}


	@ApiOperation(value = "托管出售",notes = "托管出售")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "订单编号",name = "ordersNo",required = true,dataType = "String",paramType = "query")
	})
	@GetMapping("/escrowSale")
	@ResponseBody
	public AjaxJson escrowSale(String memberId,String ordersNo){
		AjaxJson aj = new AjaxJson();
		//查询用户信息   出售人
		Member member = memberService.get(memberId);
		if (member == null){
			aj.setSuccess(false);
			aj.setMsg("用户信息有误");
		}else {
			//查询订单信息
			Orders orders = new Orders();
			orders.setOrdersNo(ordersNo);
			List<Orders> ordersList = ordersService.findList(orders);
			if (ordersList.size()>0){
				Goods goods = goodsService.get(ordersList.get(0).getGoods().getId());
				//出售价格比购买价格多15%
				BigDecimal salePrice = BigDecimal.valueOf(ordersList.get(0).getMoney()).multiply(BigDecimal.valueOf(1.13));
				//手续费为购买价格的8%
				BigDecimal charge = BigDecimal.valueOf(ordersList.get(0).getMoney()).multiply(BigDecimal.valueOf(0.07));
//				if ("2".equals(goods.getGoodsType())){
//					salePrice = BigDecimal.valueOf(ordersList.get(0).getMoney()).multiply(BigDecimal.valueOf(1.25));
//					charge = BigDecimal.valueOf(ordersList.get(0).getMoney()).multiply(BigDecimal.valueOf(0.1));
//				}
				aj.put("salePrice",salePrice);
				aj.put("charge",charge);
			}else {
				aj.setSuccess(false);
				aj.setMsg("订单信息有误");
				return aj;
			}
			Account account = new Account();
			account.setMember(member);
			List<Account> accountList = accountService.findList(account);
			if (accountList.size()>0){
				BigDecimal balance = BigDecimal.valueOf(accountList.get(0).getYue());
				aj.put("balance",balance);
			}else {
				aj.setSuccess(false);
				aj.setMsg("钱包信息有误");
				return aj;
			}
			aj.setSuccess(true);
			aj.setMsg("操作成功");
		}
		return aj;
	}


	@ApiOperation(value = "去提现",notes = "去提现")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query")
	})
	@GetMapping("/goToCashOut")
	@ResponseBody
	public AjaxJson goToCashOut(String memberId){
		AjaxJson aj = new AjaxJson();
		//查询用户信息
		Member member = memberService.get(memberId);
		if (member == null){
			aj.setSuccess(false);
			aj.setMsg("用户信息有误");
		}else {
			Account account = new Account();
			account.setMember(member);
			List<Account> accountList = accountService.findList(account);
			if (accountList.size()<=0){
				aj.setSuccess(false);
				aj.setMsg("账户信息有误");
				return aj;
			}
			Userbank userbank = new Userbank();
			userbank.setMember(member);
			List<Userbank> userbankList = userbankService.findList(userbank);
//			if (userbankList.size()<=0){
//				aj.setSuccess(false);
//				aj.setMsg("用户银行卡信息有误");
//				return aj;
//			}
			//提现费率
			List<CashCharge> charges = cashChargeService.findAllList(new CashCharge());
			aj.put("bank",userbankList.size()==0?"":userbankList.get(0));
			aj.put("balance",accountList.get(0).getYue());
			aj.put("charge",charges.get(0));
			aj.setSuccess(true);
			aj.setMsg("操作成功");
		}
		return aj;
	}


	@ApiOperation(value = "确认提现",notes = "确认提现")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "提现金额",name = "cashMoney",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "是否中国银行(0否1是)",name = "flag",required = true,dataType = "String",paramType = "query")
	})
	@PostMapping("/confirmCashOut")
	@ResponseBody
	public AjaxJson confirmCashOut(String memberId,String cashMoney,String flag){
		AjaxJson aj = new AjaxJson();
		//查询用户信息
		Member member = memberService.get(memberId);
		if (member == null){
			aj.setSuccess(false);
			aj.setMsg("用户信息有误");
		}else {
			if ("0".equals(member.getIsCollection())){
				aj.setSuccess(false);
				aj.setMsg("您暂时不可提现");
				return aj;
			}
			Jedis jedis = new Jedis();
			Long r1 = jedis.setnx(memberId+"_cash",memberId);
			if (r1 != 1){
				aj.setSuccess(false);
				aj.setMsg("操作频繁，请稍候");
				return aj;
			}else {
				jedis.expire(memberId+"_cash",5);
			}
			aj = tixianService.cashOut(member,cashMoney);
			jedis.close();
		}
		return aj;
	}



	@ApiOperation(value = "确认提货",notes = "确认提货")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "订单编号",name = "orderNo",required = true,dataType = "String",paramType = "query")
	})
	@PostMapping("/confirmTakeGoods")
	@ResponseBody
	public AjaxJson confirmTakeGoods(String memberId,String orderNo){
		AjaxJson aj = new AjaxJson();
		//查询用户信息
		Member member = memberService.get(memberId);
		if (member == null){
			aj.setSuccess(false);
			aj.setMsg("用户信息有误");
		}else {
			Orders orders = new Orders();
			orders.setOrdersNo(orderNo);
			List<Orders> ordersList = ordersService.findList(orders);
			if (ordersList.size()<=0){
				aj.setSuccess(false);
				aj.setMsg("订单信息有误");
				return aj;
			}
			//查询地址信息
			Address addressInfo = new Address();
			addressInfo.setMember(member);
			List<Address> address = addressService.findList(addressInfo);
			if (address.size()<=0){
				aj.setSuccess(false);
				aj.setMsg("请添加地址");
				return aj;
			}
			ordersList.get(0).setAddressAdd(address.get(0).getAddress());
			ordersList.get(0).setAddressMobile(address.get(0).getMobile());
			ordersList.get(0).setAddressName(address.get(0).getName());
			//修改  为 4  已提货
			ordersList.get(0).setOrdersStatus("4");
			ordersService.save(ordersList.get(0));

			//商品改为待发货

			aj.setSuccess(true);
			aj.setMsg("操作成功");
		}
		return aj;
	}

    @ApiOperation(value = "删除订单",notes = "删除订单")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query"),
            @ApiImplicitParam(value = "订单编号",name = "orderNo",required = true,dataType = "String",paramType = "query")
    })
    @PostMapping("/deleteOrder")
    @ResponseBody
    public AjaxJson deleteOrder(String memberId,String orderNo){
        AjaxJson aj = new AjaxJson();
        //查询用户信息
        Member member = memberService.get(memberId);
        if (member == null){
            aj.setSuccess(false);
            aj.setMsg("用户信息有误");
        }else {
//            Orders orders = new Orders();
//            orders.setOrdersNo(orderNo);
//            List<Orders> ordersList = ordersService.findList(orders);
//            if (ordersList.size()<=0){
//                aj.setSuccess(false);
//                aj.setMsg("订单信息有误");
//            }
//            if ("1".equals(ordersList.get(0).getOrdersStatus())){
//				Goods goods = goodsService.get(ordersList.get(0).getGoods().getId());
//				if (StringUtils.isNotBlank(goods.getOrders().getId())){
//					ordersList.get(0).setOrdersStatus("0");
//					ordersList.get(0).setTomem(new Member());
//					ordersService.save(ordersList.get(0));
//					//删除原交易记录
//					Trade trade = new Trade();
//					trade.setOrderNo(ordersList.get(0).getOrdersNo());
//					List<Trade> tradeList = tradeService.findList(trade);
//					if (tradeList.size()>0){
//						tradeList.get(0).setDelFlag("1");
//						tradeService.save(tradeList.get(0));
//						//生成对应的新的交易记录
//						Trade trade1 = new Trade();
//						trade1.setId(IdGen.uuid());
//						trade1.setOrderNo(tradeList.get(0).getOrderNo());
//						trade1.setPayType(tradeList.get(0).getPayType());
//						trade1.setGoods(tradeList.get(0).getGoods());
//						trade1.setMember(tradeList.get(0).getMember());
//						trade1.setTradeStatus("0");
//						trade1.setRemarks("付款超时，重新上架");
//						trade1.setIsNewRecord(true);
//						trade1.preInsert();
//						tradeService.save(trade1);
//					}
//				}else {
//					ordersList.get(0).setDelFlag("1");
//					ordersService.save(ordersList.get(0));
//					//删除原交易记录
//					Trade trade = new Trade();
//					trade.setGoods(goods);
//					List<Trade> tradeList = tradeService.findList(trade);
//					if (tradeList.size()>0){
//						tradeList.get(0).setDelFlag("1");
//						tradeService.save(tradeList.get(0));
//						//生成对应的新的交易记录
//						Trade trade1 = new Trade();
//						trade1.setPayType(tradeList.get(0).getPayType());
//						trade1.setGoods(tradeList.get(0).getGoods());
//						trade1.setMember(tradeList.get(0).getMember());
//						trade1.setTradeStatus("0");
//						trade1.setRemarks("付款超时，重新上架");
//						tradeService.save(trade1);
//					}
//				}
//
//				//对应商品改为出售中
//				goods.setGoodsStatus("1");
//				goodsService.saveGoodsForInterface(goods);
//
//				aj.setSuccess(true);
//				aj.setMsg("订单取消");
//			}
        }
        return aj;
    }


	@ApiOperation(value = "查询订单数量",notes = "查询订单数量")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "订单类型（0:购买订单1:出售订单）",name = "orderType",required = true,dataType = "String",paramType = "query")
	})
	@PostMapping("/selectOrderNum")
	@ResponseBody
	public AjaxJson selectOrderNum(String memberId,String orderType){
		AjaxJson aj = new AjaxJson();
		//查询用户信息
		Member member = memberService.get(memberId);
		if (member == null){
			aj.setSuccess(false);
			aj.setMsg("用户信息有误");
		}else {
			List<Object> list = new ArrayList<>();
			if ("1".equals(orderType)){
				Map<String,Object> map = new HashMap<>();
				Orders orders = new Orders();
				//上架中
				orders.setOrdersStatus("0");
				orders.setMember(member);
				List<Orders> ordersList = ordersService.findList(orders);

				map.put("orderType","0");
				map.put("listNum",ordersList.size());
				list.add(map);

				Map<String,Object> map1 = new HashMap<>();
				Orders orders1 = new Orders();
				//订单状态  等待付款
				orders1.setOrdersStatus("1");
				orders1.setMember(member);
				List<Orders> ordersList1 = ordersService.findList(orders1);

				map1.put("orderType","1");
				map1.put("listNum",ordersList1.size());
				list.add(map1);

				Map<String,Object> map2 = new HashMap<>();
				Orders orders2 = new Orders();
				//订单状态  待确认
				orders2.setOrdersStatus("2");
				orders2.setMember(member);
				List<Orders> ordersList2 = ordersService.findList(orders2);
				map2.put("orderType","2");
				map2.put("listNum",ordersList2.size());
				list.add(map2);

				Map<String,Object> map3 = new HashMap<>();
				Orders order3 = new Orders();
				//订单状态   交易完成
				order3.setOrdersStatus("3");
				//已出售
//				order1.setIsSale("0");
				order3.setMember(member);
				List<Orders> orderList3 = ordersService.findList(order3);
				map3.put("orderType","3");
				map3.put("listNum",orderList3.size());
				list.add(map3);

			}
			if ("0".equals(orderType)){

				Map<String,Object> map = new HashMap<>();
				Orders order2 = new Orders();
				//订单状态  等待付款
				order2.setOrdersStatus("1");
				order2.setTomem(member);
				List<Orders> orderList2 = ordersService.findList(order2);
				map.put("orderType","0");
				map.put("listNum",orderList2.size());
				list.add(map);

				Map<String,Object> map1 = new HashMap<>();
				Orders order = new Orders();
				//订单状态  待确认
				order.setOrdersStatus("2");
				order.setTomem(member);
				List<Orders> orderList = ordersService.findList(order);
				map1.put("orderType","1");
				map1.put("listNum",orderList.size());
				list.add(map1);

				Map<String,Object> map2 = new HashMap<>();
				Orders order1 = new Orders();
				//订单状态   交易完成
				order1.setOrdersStatus("3");
				//未出售
				order1.setIsSale("1");
				order1.setTomem(member);
				List<Orders> orderList1 = ordersService.findList(order1);
				map2.put("orderType","2");
				map2.put("listNum",orderList1.size());
				list.add(map2);

				Map<String,Object> map3 = new HashMap<>();
				Orders order3 = new Orders();
				//订单状态  已提货
				order3.setOrdersStatus("4");
				order3.setTomem(member);
				List<Orders> orderList3 = ordersService.findList(order3);
				map3.put("orderType","3");
				map3.put("listNum",orderList3.size());
				list.add(map3);

				Map<String,Object> map4 = new HashMap<>();
				Orders order4 = new Orders();
				//订单状态   交易完成
				order4.setOrdersStatus("3");
				//已出售
				order4.setIsSale("0");
				order4.setTomem(member);
				List<Orders> orderList4 = ordersService.findList(order4);
				map4.put("orderType","4");
				map4.put("listNum",orderList4.size());
				list.add(map4);
			}
			aj.put("list",list);
			aj.setSuccess(true);
		}
		return aj;
	}


	@ApiOperation(value = "抢购",notes = "抢购")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "用户id",name = "memberId",required = true,dataType = "String",paramType = "query"),
			@ApiImplicitParam(value = "商品类型",name = "goodsType",required = true,dataType = "String",paramType = "query")
	})
	@PostMapping("/qianggou")
	@ResponseBody
	public AjaxJson qianggou(String memberId,String goodsType){
		AjaxJson aj = new AjaxJson();
		//查询用户信息
		Member member = memberService.get(memberId);
		if (member == null){
			aj.setSuccess(false);
			aj.setMsg("用户信息有误");
		}else {
			try {
				SimpleDateFormat df = new SimpleDateFormat("HH:mm");//设置日期格式
				Date nowTime =df.parse(df.format(new Date()));
				//新人区规定时间
				Date beginTime = df.parse("09:00");
				Date endTime = df.parse("09:30");
				//入门区规定时间
				Date beginTime1 = df.parse("14:30");
				Date endTime1 = df.parse("15:00");

				Date beginTime2 = df.parse("20:00");
				Date endTime2 = df.parse("20:30");
				//调用判断方法是否在规定时间段内
				boolean isTime = DateUtils.timeCalendar(nowTime, beginTime, endTime);
				boolean isTime1 = DateUtils.timeCalendar(nowTime, beginTime1, endTime1);
				boolean isTime2 = DateUtils.timeCalendar(nowTime, beginTime2, endTime2);
				if (!isTime && "0".equals(goodsType)){
					if (!"7".equals(member.getRemarks())){
						aj.setSuccess(false);
						aj.setMsg("匹配时间段为09:00~09:30！");
						return aj;
					}

				}
				if (!isTime1 && "1".equals(goodsType)){
					if (!"7".equals(member.getRemarks())){
						aj.setSuccess(false);
						aj.setMsg("匹配时间段为14:30~15:00！");
						return aj;
					}

				}
				if (!isTime2 && "2".equals(goodsType)){
					if (!"7".equals(member.getRemarks())){
						aj.setSuccess(false);
						aj.setMsg("匹配时间段为20:00~20:30！");
						return aj;
					}
				}
			}catch (ParseException e){
				e.printStackTrace();
			}
			//todo 20s抢单
			Orders qOrders = new Orders();
			qOrders.setTomem(member);
			qOrders.setOrdersStatus("1");
			List<Orders> list = ordersService.findList(qOrders);
			if (list.size()>0){
				//系统当前时间
				Long now = System.currentTimeMillis();
				//购买完成时间
				Long boughtTime = list.get(0).getUpdateDate().getTime();
				if ((now-boughtTime)/(1000)<20){
					aj.setSuccess(false);
					aj.setMsg("操作频繁，请稍后重试。");
					return aj;
				}
			}
			//判断限制购买订单数
			Integer amount = member.getAmount();
			//如果添加了限制
			if (amount != null){
				Orders selectOrder = new Orders();
				Goods goods = new Goods();
				goods.setGoodsType(goodsType);
				selectOrder.setTomem(member);
				selectOrder.setGoods(goods);
				Integer ordersAmount = ordersMapper.selectOrdersAmount(selectOrder);
				if (ordersAmount >= amount){
					aj.setSuccess(false);
					aj.setMsg("您当前分区购买订单过多，请等卖出后再抢购。");
					return aj;
				}
			}
			Jedis jedis = new Jedis("localhost",6379);
			Long result = jedis.setnx("snap_up",memberId);
			if (result == 1){
				//设置有效期10秒
				jedis.expire("snap_up",10);
				aj = ordersService.qianggouGoods(member,goodsType);
				jedis.del("snap_up");
			}else {
				aj.setSuccess(false);
				aj.setMsg("当前抢购人数过多，请重试！");
				return aj;
			}

		}
		return aj;
	}


}
